package com.service;

import java.util.Vector;
import java.util.concurrent.CountDownLatch;

import com.model.ProxyIp;

public class ConnectThread extends Thread{
	
	private ProxyIp proxyip;
	private Vector<ProxyIp> avaliableIp;
	private CountDownLatch latch;
	public ConnectThread(ProxyIp proxyip,CountDownLatch latch,Vector<ProxyIp> avaliableIp) {
		super();
		this.proxyip = proxyip;
		this.avaliableIp = avaliableIp;
		this.latch = latch;
	}
	@Override
	public void run() {
		super.run();
		String ip = proxyip.getIp();
		int port = Integer.parseInt(proxyip.getPort());
		long t1 = System.currentTimeMillis();
    	if(ProxyIpService.ipAvilable(ip,port)){
    		long t2 = System.currentTimeMillis()-t1;
    		avaliableIp.add(proxyip);
    		System.out.println("\n pass: "+ip+"  "+port+"  "+proxyip.getLocation()+"  "+this.getName()+"  访问baidu耗时: "+t2+"ms");
    	}
    	latch.countDown();
	}
}
